package br.com.Servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.Dao.PaginaDao;
import br.com.Modelo.Pagina;

/**
 * Servlet implementation class teste
 */
@WebServlet(name = "paginas", urlPatterns = {
"/click",
"/mercadin",
"/techinfo",
"/novaera",
"/bretas",
"/e",
"/f",
"/g",
"/h",
"/j",
}) 
public class teste extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public teste() {
        super();
     
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		System.out.println(request.getParameter("pagina"));
		
		String pagina = request.getParameter("pagina");
		
		String dadosUrl = request.getParameter("dadosUrl");
		
		String dadosPagina = request.getParameter("dadosPagina");
		
		System.out.println("JS=="+dadosPagina);
		System.out.println("URL="+request.getRequestURI());
		System.out.println("URL="+request.getContextPath());
		System.out.println("URL="+request.getServletPath());
		
		if(request.getServletPath().equals("/click")){
			
		
		    
			Pagina page = new Pagina();
			PaginaDao dao = new PaginaDao();
			page = dao.getPaginaComplet("clickcatalao");
			
			request.setAttribute("pagina", page);
			
			
			RequestDispatcher rd = request
				    .getRequestDispatcher("pages/loja.jsp");
				try {
				    rd.forward(request,response);
				} catch (ServletException e) {
				    // TODO Auto-generated catch block
				    e.printStackTrace();
				} catch (IOException e) {
				    // TODO Auto-generated catch block
				    e.printStackTrace();
				}
			
		}
		
	   if(request.getServletPath().equals("/mercadin")){
		   
			Pagina page = new Pagina();
			PaginaDao dao = new PaginaDao();
			page = dao.getPaginaComplet("mercadin");
			
			request.setAttribute("pagina", page);
			
			RequestDispatcher rd = request
				    .getRequestDispatcher("pages/loja.jsp");
				try {
				    rd.forward(request,response);
				} catch (ServletException e) {
				    // TODO Auto-generated catch block
				    e.printStackTrace();
				} catch (IOException e) {
				    // TODO Auto-generated catch block
				    e.printStackTrace();
				}
			
		}
	
	if(request.getServletPath().equals("/techinfo")){
		
		
	    
		Pagina page = new Pagina();
		PaginaDao dao = new PaginaDao();
		page = dao.getPaginaComplet("techinfo");
		
		request.setAttribute("pagina", page);
		
		
		RequestDispatcher rd = request
			    .getRequestDispatcher("pages/loja.jsp");
			try {
			    rd.forward(request,response);
			} catch (ServletException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			} catch (IOException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			}
		
	}
	
	if(request.getServletPath().equals("/novaera")){		
		
	    
		Pagina page = new Pagina();
		PaginaDao dao = new PaginaDao();
		page = dao.getPaginaComplet("novaera");
		
		request.setAttribute("pagina", page);
		
		
		RequestDispatcher rd = request
			    .getRequestDispatcher("pages/loja.jsp");
			try {
			    rd.forward(request,response);
			} catch (ServletException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			} catch (IOException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			}
		
	}
		
	if(request.getServletPath().equals("/bretas")){		
		
	    
		Pagina page = new Pagina();
		PaginaDao dao = new PaginaDao();
		page = dao.getPaginaComplet("bretas");
		
		request.setAttribute("pagina", page);
		
		
		RequestDispatcher rd = request
			    .getRequestDispatcher("pages/loja.jsp");
			try {
			    rd.forward(request,response);
			} catch (ServletException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			} catch (IOException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			}
		
	}
	
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
